Ext.namespace("Milan.pagejs.page_index");
Ext.namespace("Ext.milan.pagejs.session");
var TAB_SIZE = 10;
var diswin;
Milan.pagejs.page_index.updateDBSessionFailureCount = 0;

Milan.pagejs.page_index.buildIndex = function(a) {
    Milan.pagejs.page_index.setSizes();
    Milan.tabbarManager.buildMainTabber();
    Milan.tabbarManager.buildDesktop(a);
    Milan.tabbarManager.createMainMenu();
    Event.observe(document, "keydown",
    function(b) {
        var c = b || window.event;
        if (c.keyCode == 27) {
            Milan.widget.closeCurrentDialog()
        }
    });
    if (! (jQuery.browser.msie && jQuery.browser.version.indexOf("6") >= 0)) {
        Milan.pagejs.page_index.windowResize()
    }
    if (a && a < 0) {
        $("loadingDiv").hide();
        $("trueLoadingDiv").hide();
        return
    }
};
Milan.pagejs.page_index.isRun = true;
Milan.pagejs.page_index.isAlert = false;

Milan.pagejs.page_index.top_quit = function() {
    Milan.ajaxutility.setLoadingDivHeight();
    $("loadingDiv").show();
    var b, k, h, f, g, c, j;
    var j = $("dialogDiv");
    k = document.createElement("DIV");
    h = document.createElement("DIV");
    f = document.createElement("SPAN");
    g = document.createElement("input");
    g.type = "button";
    g.value = "确定";
    c = document.createElement("input");
    c.type = "button";
    c.value = "取消";
    var i = document.createTextNode("　　");
    var a = document.createElement("DIV");
    a.className = "log_sys";
    a.innerHTML = '<div class="flogo"><img src="' + $("loaddingLogoUrl").value + '" width="45px" height="45px"/></div><div class="risystem">' + $("loaddingLogoName").value + "<span>> OFFICIE AUTOMATION SYSTEM V3.0</span></div>";
    k.id = "LogoutWin";
    k.className = "log-win";
    k.style.zIndex = 9999;
    h.className = "log-con";
    f.innerHTML = "您确定要退出系统吗？";
    h.appendChild(a);
    h.appendChild(f);
    var d = document.createElement("DIV");
    g.onclick = function() {
        g.disabled = true;
        c.disabled = true;
        f.innerHTML = "正在退出..请稍候...";
        Milan.ajaxutility.formSubmit({
            url: "member_logout.do",
            method: "post",
            success: function(l, m) {
                window.location.reload()
            }
        })
    };
    c.onclick = function() {
        j.removeChild(k);
        $("loadingDiv").hide()
    };
    d.appendChild(g);
    d.appendChild(i);
    d.appendChild(c);
    h.appendChild(d);
    k.appendChild(h);
    j.appendChild(k)
};
Milan.pagejs.page_index.updateCurrentTab = function(b, a) {
/*    if (!a) {
        a = Milan.tabbarManager.getActiveTab()
    }
    */
    Milan.ajaxutility.updateContainer('middleFrame', b)
};
Milan.pagejs.page_index.updateCurrentTabByUrl = function(c, b) {
    if (!b) {
        b = {}
    }
    b.url = c;
    var a = b.success;
    b.success = function(d) {
        if (b.beforeUpdate) {
            b.beforeUpdate(d)
        }
        Milan.pagejs.page_index.updateCurrentTab(d.responseText);
        if (a) {
            a(d)
        }
    };
    Milan.ajaxutility.formSubmit(b)
};
Milan.pagejs.page_index.updateCurrentTabByForm = function(c, b) {
    if (!b) {
        b = {}
    }
    b.form = c;
    var a = b.success;
    b.success = function(d) {
        if (b.beforeUpdate) {
            b.beforeUpdate(d)
        }
        Milan.pagejs.page_index.updateCurrentTab(d.responseText);
        if (a) {
            a(d)
        }
    };
    Milan.ajaxutility.formSubmit(b)
};
Milan.pagejs.page_index.relogin = function(userName, userPwd,domain, skins, successCallBack) {
    var url = "member_autoLogin.do?username=" +userName+"&password=" + userPwd+"&domain=" + domain;
    Milan.ajaxutility.formSubmit({
        url: url,
        success: function(response, option) {
            var result = response.responseXML.getElementsByTagName("result")[0].firstChild.nodeValue;
            var message = response.responseXML.getElementsByTagName("error-message")[0].firstChild.nodeValue;
            var errorType = response.responseXML.getElementsByTagName("error-type")[0].firstChild.nodeValue;
            if (!eval(result) && (errorType != 2)) {
            	alert('3');
                Milan.commonutils.createDelayNotifyModel("提示", message)
            } else {
                if (successCallBack) {
                    successCallBack()
                }
            }
        },
        failure: function(response, options) {
            Milan.commonutils.createDelayNotifyModel("错误", "尝试登录时发生错误！<br>请检查网络连接情况或联系系统管理员，谢谢！")
        }
    })
};
Milan.pagejs.page_index.showDebugForm = function() {
    var a = "/debug.html";
    debugWin = Milan.commonutils.createModelPop({
        title: "Debug",
        height: "330px",
        width: "800px"
    });
    Milan.ajaxutility.updateContentUseAjax("post", a, debugWin)
};

Milan.pagejs.page_index.setSizes = function() {
    if (!Milan.navigator.isAndroid) {
        $("middleFrame").style.height = (Milan.pagejs.page_index.getWinSize().height - $("topFrame").offsetHeight - $("bottomFrame").offsetHeight) + "px"
    }
};
Milan.pagejs.page_index.viewUserDetail = function(d, b, a) {
    if (!a) {
        a = window.event
    }
    var c = "user/view.do?userid=" + d;
    userDetailWin = Milan.commonutils.createModelPop({
        title: b || "人员信息",
        height: "300px",
        width: "500px"
    });
    Milan.ajaxutility.updateContentUseAjax("post", c, userDetailWin)
};
Milan.pagejs.page_index.settingPwd = function() {
    var c = "user/settingPwd.do";
    userDetailWin = Milan.commonutils.createModelPop({
        title: "修改密码",
        height: "300px",
        width: "500px"
    });
    Milan.ajaxutility.updateContentUseAjax("post", c, userDetailWin)
};

Milan.pagejs.page_index.showDialog = function(a, c, b) {
    Milan.pagejs.page_index.win = Milan.commonutils.createModelPop({
        title: c,
        width: b + "px"
    });
    Milan.ajaxutility.updateContentUseAjax("post", a, Milan.pagejs.page_index.win)
};

Milan.pagejs.page_index.getWinSize = function() {
    var a, b;
    if (window.innerHeight) {
        a = window.innerWidth;
        b = window.innerHeight
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            a = document.documentElement.clientWidth;
            b = document.documentElement.clientHeight
        } else {
            if (document.body) {
                a = document.body.clientWidth;
                b = document.body.clientHeight
            }
        }
    }
    return {
        width: a,
        height: b
    }
};
Milan.pagejs.page_index.windowResize = function() {
    var b = Milan.pagejs.page_index.getWinSize().height;
    var a = Milan.pagejs.page_index.getWinSize().width;
    Milan.resizeHeight = 0;
    Milan.resizeWidth = 0;
    window.onresize = function() {
        if (typeof Milan == "undefined") {
            return
        }
        if ($("loadingDiv").style.display != "none") {
            Milan.ajaxutility.setLoadingDivHeight()
        }
        Milan.pagejs.page_index.setSizes();
        jQuery(".dhx_tabcontent_zone").css("height", jQuery(".dhx_tabcontent_zone").parent().height() - jQuery(".dhx_tabcontent_zone").prev().height());
        jQuery("#portal_div").css("height", (jQuery(".dhx_tabcontent_zone").find("div[tab_id='mainTabPanel']").height() - jQuery("#main_submenu").height()) + "px");
        var f = b - Milan.pagejs.page_index.getWinSize().height;
        var d = a - Milan.pagejs.page_index.getWinSize().width;
        b = Milan.pagejs.page_index.getWinSize().height;
        a = Milan.pagejs.page_index.getWinSize().width;
        if (f != 0 || d != 0) {
            Milan.resizeHeight = f;
            Milan.resizeWidth = d;
            for (var c = Milan.ajaxutility.grids.length - 1; c >= 0; c--) {
                Milan.ajaxutility.grids[c].needResize = true
            }
            Milan.tabbarManager.reRenderActiveTab()
        }
    }
};
Milan.pagejs.page_index.resizeGrid = function(c, f) {
    f = f || 0;
    if (f == 0) {
        return
    }
    if (c.entBox && c.objBox) {
        var a = 0,
        g = 0,
        h = 0,
        d = jQuery(c.objBox).parents("form"),
        i = 0;
        jQuery(c.hdrBox).css("width", Milan.pagejs.page_index.getWinSize().width - 18);
        Milan.ajaxutility.transferGrid.resizeColumnWidth(c);
        h = c.objBox.clientWidth - 11 - 8;
        var b = jQuery(c.hdrBox).parents("form").find(".td_affair .td_info2 .info_btn").prop("clientWidth");
        jQuery(c.hdrBox).parents("form").find(".td_affair .td_info2").each(function(j, k) {
            jQuery(k).find(".info_btn").show();
            jQuery(k).css({
                width: h
            }).find(".info_startRemark").css({
                width: h - b - 48
            });
            jQuery(k).find(".info_btn").hide()
        });
        a = jQuery(c.objBox).prop("offsetHeight");
        g = jQuery(c.objBox).prop("scrollHeight");
        if (a < g) {
            c.enableAutoHeight(true, jQuery(c.entBox).height() - f, true)
        }
        if (d && d.height() != 0) {
            i = parseInt(d.parent().parent().parent().css("height"));
            if (f != 0) {
                i = i - 30
            }
            if (i < d.height()) {
                f = d.height() - i;
                c.enableAutoHeight(true, jQuery(c.entBox).height() - f, true)
            }
        }
        c.setSizes()
    }
};
